<? if (sizeof($SCRIPT['link'])) { 

	if ($_page = ob_get_clean()) { ob_start(); ?>

<!--[if lte IE 8]>
<script src="<?=implode('"></script><script src="', $SCRIPT['link'])?>"></script>
			
<script>
var tags = "abbr|article|aside|audio|canvas|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video".split("|");
	for(var i in tags) { document.createElement(tags[i]) };

	head = {
			js: function(url) { return true }
		,	ready: function(func) { if (window && window.$) $(func) }
	};
</script>
<![endif]-->			

		<?=str_replace('<script></script>', ob_get_clean(), $_page)?><?
	}


?><script type="text/javascript"><?

	if (sizeof($SCRIPT['link'])) { ?>head.js("<?=implode('"); head.js("', $SCRIPT['link'])?>");<? } ?><?

	if (sizeof($SCRIPT['inline'])) {



		foreach($SCRIPT['inline'] as $k => $v) {

			preg_match_all("/<script([^>]*)>(.*)<\/script>/iUs", $v, $res);

			if ($res && sizeof($res[1])) {
				foreach($res[1] as $k1 => $v1) {
					preg_match('/src=[\'"](.*)[\'"]/iUs', $v1, $res1);

					if ($res1 && sizeof($res1[1])) { 
						?>head.js("<?=h($res1[1])?>");<? 
					}
					
				}
			}

			if ($res && sizeof($res[2])) {	// script(s) are enclosed into the <script> tag(s). extract 'em.

				?>head.ready(function(){<?=implode("\n", $res[2])?>});<?

			} else {	//	clean js
				?>head.ready(function(){<?="$v\n"?>});<?
			}
		}
	}

   

?></script><?

}

if (sizeof($SCRIPT['tag'])) { ?><?=implode("\n", $SCRIPT['tag'])?><? }
